<?php 
class d extends show
{
    public function __construct(){
        date_default_timezone_set('PRC');
        include_once $_SERVER['DOCUMENT_ROOT'].'/Pmodel/dbli.class.php';
        include_once $_SERVER['DOCUMENT_ROOT'].'/Pmodel/NumForChek.class.php';
        session_start();
    }
    public function data()
    {
        //
        date_default_timezone_set('PRC');
        $db = new dbli($GLOBALS['C']);
        $sql="SELECT * FROM `pks_k` order by gtime desc limit 0 ,10";
        $arr=$db->select($sql);
        foreach ($arr as $key=>$value)
        {
            $arr[$key]['gtime']=date('Y-m-d H:i:s',$value['gtime']);
        }
       
        echo json_encode($arr);
    }
    
    
    public function cexiao()
    {
        $tid=is_numeric($_POST['tid'])?$_POST['tid']:0;
        $ID=is_numeric($_POST['ID'])?$_POST['ID']:0;
        $db = new dbli($GLOBALS['C']);
        $sqle="SELECT * FROM `wx_pkd` WHERE `tagf`=0 and `tagk`=1 order by ID ASC limit 0,1";
        $sql2="select * from user_log where ID=$tid and status=1";
        $sql4="select * from wx_manage where ID=$ID";
        
        $qh=$db->select($sqle);
        $data=$db->select($sql2);
        $udate=$db->select($sql4);
        
        $sql3="select * from wx_pk10 where ID={$data[0]['tid']}";
        $tz=$db->select($sql3);
        
        if($qh[0]['issue']!=$data[0]['qh']){
             die('本期已封盘 无法撤销');
        }
        
        $nowmoney=$udate[0]['money']+$data[0]['money'];
        $db->U_D('START TRANSACTION');
        
        $sql1="update user_log set dit=1 where ID=$tid"; 
        $sql2="update wx_manage set money=$nowmoney where ID=$ID";
        $sql3="update wx_pk10 set is_money=4 where ID={$data[0]['tid']}";
        $sql4="INSERT INTO `user_log`(`uid`, `money`, `old_money`, `new_money`, `type`, `status`, `remark`, `issue`, `gtime`, `qh`, `tid`, `dit`) VALUES ($ID,{$data[0]['money']},{$udate[0]['money']},$nowmoney,1,3,'撤销竞猜回点,期号：{$qh[0]['issue']},竞猜结果：【{$tz[0]['stype']}/{$tz[0]['nums']}/{$tz[0]['money']}】','{$qh[0]['issue']}',".time().",'{$qh[0]['issue']}',{$data[0]['tid']},0)";
        if($db->U_D($sql1) && $db->U_D($sql2) && $db->U_D($sql3) && $db->add($sql4)){
            $db->U_D('COMMIT');
            die('撤回竞猜成功');
        }else{
            $db->U_D('ROLLBACK');
            file_put_contents('/ch.txt', $sql1.PHP_EOL.$sql2.PHP_EOL.$sql3.PHP_EOL.$sql4.PHP_EOL);
            die('撤回竞猜失败');
        }
    }
    
    public function findM()
    {
      date_default_timezone_set('PRC');
      $d=$_POST['i'];
      $idd=$_POST['id'];
      switch ($d) {
          case 0:
               $str="`gtime` between ".strtotime(date("Y-m-d"))." and ".strtotime(date("Y-m-d")." 23:59:59")."";
                break;
          case 1:
                $time=time()-3600*24;
                $str="`gtime` between ".strtotime(date("Y-m-d",$time))." and ".strtotime(date("Y-m-d",$time)." 23:59:59")."";
                break;
              
         case 2:
                $time=time()-3600*24*2;
                $str="`gtime` between ".strtotime(date("Y-m-d",$time))." and ".strtotime(date("Y-m-d",$time)." 23:59:59")."";
                break;
         case 3:
                $str="";
                break;
         default:
                $str="";
                break;
      }
    
      $sql="SELECT * FROM `user_log` where 1=1 and uid=$idd ";
      if($str){
          $sql.=" and $str ";
      }
      $sql.=" order by ID desc limit 0,300";
      
      $db = new dbli($GLOBALS['C']);
      $arr=$db->select($sql);
      $mf=$GLOBALS['C']['LX'];
      
      $sqle="SELECT * FROM `wx_pkd` WHERE `tagf`=0 and `tagk`=1 order by ID ASC limit 0,1";
      $qh=$db->select($sqle);
      $resultArr=array();
      foreach($arr as $k=>$v){
          if($qh[0]['issue']==$v['qh'] && $v['status']==1){
              $arr[$k]['cx']=1;
          }
        
          $arr[$k]['gtime']=date('H:i:s',$v['gtime']);
          $arr[$k]['status']=$mf[$v['status']];
         /*  if($arr[$k]['type']==1){
              $arr[$k]['money']="<b style='color:green'>{$v['money']}</b>";
          }elseif($arr[$k]['type']==2){
              $arr[$k]['money']="<b style='color:red'>{$v['money']}</b>";
          }
          $arr[$k]['new_money']="<b style='color:green'>{$v['new_money']}</b>"; */
          
       //   $arr[$k]['money']=(int)$arr[$k]['money'];
          
          $onedate=date('Y-m-d',$v['gtime']);
      
          $resultArr[$onedate][]= $arr[$k];
      }
      
      //file_put_contents($_SERVER['DOCUMENT_ROOT'].'/cache/a.txt', json_encode($resultArr));
      
      
      echo json_encode($resultArr);
    }
    
    
    
    public function getmoney()
    {
        $id=intval($_GET['i']);
      
        $db = new dbli($GLOBALS['C']);
        $arr=$db->select("select money from wx_manage where ID=$id limit 0,1");
        echo $arr[0]['money']>0?$arr[0]['money']:0;
    }
    
    
//http://域名/?G=d/setPK10
    public function setPK10()
    {
        $t=time();
        $qs=300;
        $db = new dbli($GLOBALS['C']);
        $sql="select * from pks_k where games=1 and gtime<$t order by gtime desc limit 0,1";
        $message=$db->select($sql);
        $ymd=date('Y-m-d');
        $time1=strtotime($ymd.' 09:07:00');
        $time2=strtotime($ymd.' 23:57:00');
        if($message[0]['gtime']>$time1 && $message[0]['gtime']<$time2){
           $old_issue=$message[0]['issue']+($time2-$message[0]['gtime'])/300;
           $tts=strtotime($time2);
           $issue=$old_issue+1;
           $sql="select * from `wx_pkd` where issue='$issue'";
           $newdates=$db->select($sql);
           //没有数据进行明天数据的插入
           if(!$newdates){
               $kptime=strtotime(date('Y-m-d',strtotime($ymd)+24*3600).' 09:02:50')+25;
               $sql="INSERT INTO `wx_pkd`( `issue`, `oktime`, `fp`, `kp`, `game`, `dtime`, `ktime`, `tagf`, `tagk`) VALUES ";
               for($i=0;$i<179;$i++){
                   $fptime=$kptime+$qs-$fp-85;
                   $oktime=$kptime+$qs;
                   $sql.="('$issue','$oktime','$fptime','$kptime',1,".time().",'".date('Y-m-d H:i',$oktime)."',0,0),";
                   $issue++;
                   $kptime+=300;
               }
               $sql=substr($sql,0,strlen($sql)-1);
               $db->add($sql);
           }
        }
    }

    ////http://域名/?G=d/setft
    
    public function setft()
    {
        $t=time();
        $qs=300;
        $db = new dbli($GLOBALS['C']);
        $ymd=date('Y-m-d');
        $time1=$ymd.' 23:54:00';
        $old_issue=date('Ymd').'130';
        $issue=$old_issue+2;
        $sql="select * from `wx_pkd` where issue='$issue'";
        $newdates=$db->select($sql);
        //没有数据进行明天数据的插入
        if(!$newdates){
            $kptime=strtotime($ymd.'23:59:45')+5;
            $sql="INSERT INTO `wx_pkd`( `issue`, `oktime`, `fp`, `kp`, `game`, `dtime`, `ktime`, `tagf`, `tagk`) VALUES ";
            for($i=0;$i<49;$i++){
                $fptime=$kptime+$qs-$fp-60;
                $oktime=$kptime+$qs;
                $sql.="('$issue','$oktime','$fptime','$kptime',2,".time().",'".date('H:i',$oktime)."',0,0),";
                $issue++;
                $kptime+=300;
            }
            $sql=substr($sql,0,strlen($sql)-1);
            $db->add($sql);
        }
    }
}